import logging

from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

import sys
sys.path.append(r'..')

from web_base.base_page_asset import BasePage

class AssetPage(BasePage):
    url = r'bsams/front/asset/asset_list.do'
    #新增定位
    add_btn_loc = (By.CLASS_NAME,'button_true')
    add_title_loc = (By.ID,'title')
    add_providerId_loc = (By.ID,'providerId')
    add_storageId_loc = (By.ID,'storageId')
    add_ok_btn_loc = (By.XPATH,'//*[@id="fm_new"]/div/div[1]/div/div[1]')
    #修改定位
    update_btn_loc = (By.XPATH, '/html/body/div[2]/div/div[2]/div[2]/div[3]/table/tbody/tr[2]/td[8]/a[1]')
    update_title_loc = (By.ID, 'title')
    update_storageId_loc = (By.ID, 'storageId')
    update_providerId_loc = (By.ID, 'providerId')
    update_ok_btn_loc = (By.XPATH, '//*[@id="fm_new"]/div/div[1]')
    #资产借用定位
    asset_lend_btn_loc = (By.XPATH, '/html/body/div[2]/div/div[2]/div[2]/div[3]/table/tbody/tr[2]/td[8]/a[2]')
    lend_departId_loc = (By.ID, 'departId')
    lend_remark_loc = (By.ID, 'remark')
    lend_ok_btn_loc = (By.XPATH, '//*[@id="fm_new"]/div/div[1]')
    #资产归还定位
    asset_return_btn_loc = (By.XPATH, '/html/body/div[2]/div/div[2]/div[2]/div[3]/table/tbody/tr[2]/td[8]/a[2]')
    return_btn_ok_loc = (By.XPATH, '//*[@id="cboxLoadedContent"]/div/div/div[2]/div[2]/div[1]')

    def asset_add(self, title, providerId, storageId):
        self.open()
        self.ele_click(self.add_btn_loc)
        sleep(1)
        self.input_ele(self.add_title_loc,title)
        sleep(1)
        self.ele_select(self.add_providerId_loc,providerId)
        sleep(1)
        self.ele_select(self.add_storageId_loc,storageId)
        sleep(1)
        self.ele_click(self.add_ok_btn_loc)
        sleep(2)
        text = self.get_alert_text()
        self.alert_click()
        return text

    def asset_update(self, title, storageId, providerId):
        self.open()
        self.ele_click(self.update_btn_loc)
        sleep(1)
        self.ele_clear(self.update_title_loc)
        sleep(1)
        self.input_ele(self.update_title_loc, title)
        sleep(1)
        self.ele_select(self.update_storageId_loc, storageId)
        sleep(1)
        self.ele_select(self.update_providerId_loc, providerId)
        sleep(1)
        self.click(self.update_ok_btn_loc)
        sleep(1)
        text = self.get_alert_text()
        self.alert_click()
        return text
    def asset_lend(self,departId,remark):
        self.open()
        sleep(1)
        self.ele_click(self.asset_lend_btn_loc)
        sleep(1)
        self.ele_select(self.lend_departId_loc,departId)
        sleep(1)
        self.ele_clear(self.lend_remark_loc)
        sleep(1)
        self.input_ele(self.lend_remark_loc,remark)
        sleep(1)
        self.ele_click(self.lend_ok_btn_loc)
        sleep(1)
        text = self.get_alert_text()
        self.alert.click()
        return text
    def asset_return(self):
        self.open()
        sleep(1)
        self.ele_click(self.asset_return_btn_loc)
        sleep(1)
        self.ele_click(self.return_btn_ok_loc)
        sleep(3)
        text = self.get_alert_text()
        self.alert.click()
        return text
    def address_find(self):
        pass
        # self.dr.find_element(By.XPATH, '//*[@id="leftmenu_asset_storage"]/div[1]/a/img').click()
        # sleep(1)
        # self.dr.find_element(By.ID, 'status').click()
        # sleep(1)
        # self.dr.find_element(By.CSS_SELECTOR, '#status > option:nth-child(2)').click()
        # sleep(1)
        # self.dr.find_element(By.CLASS_NAME, 'input_gry').send_keys('总经理办公室')
        # sleep(1)
        # self.dr.find_element(By.CLASS_NAME, 'search_button').click()
        # sleep(1)
    def apply_find(self):
        pass
        # self.dr.find_element(By.XPATH, '//*[@id="leftmenu_asset_provider"]/div[1]/a/img').click()
        # sleep(1)
        # self.dr.find_element(By.CLASS_NAME, 'select_gry').click()
        # sleep(1)
        # self.dr.find_element(By.CSS_SELECTOR, '#fmsearch > div:nth-child(1) > select > option:nth-child(3)').click()
        # sleep(1)
        # self.dr.find_element(By.CLASS_NAME, 'input_gry').send_keys('北京合力科技有限公司')
        # sleep(1)
        # self.dr.find_element(By.CLASS_NAME, 'search_button').click()
        # sleep(1)



if __name__ == '__main__':
    url=r'http://172.16.22.105:8080/bsams/front/login.do'
    dr=webdriver.Chrome(options=options)
    dr.get(url)
    dr.maximize_window()
    id='1'
    username='test11'
    password='1234567'
    tel='18638798023'
    asms=Asms(dr)
    asms.login(id,username,password,identify='shtd')
    # asms.asset_add()
    # asms.asset_update()
    # asms.logout()
    # asms.asset_lend()
    # asms.asset_borrow()
    # asms.personal_tel()
    # asms.personal_pwd()
    # asms.address_find()
    # asms.apply_find()
